import win32com.client
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:/Users/hyq/Desktop/Alarm.mdb;'
conn.Open(DSN)

rs = win32com.client.Dispatch(r'ADODB.Recordset')
#表的名字
rs_name = "Alarm202002"
rs.Open('[' + rs_name + ']', conn, 1, 3)
sql = "Select VarName FROM " + rs_name + " where AlarmValue = 0"
data = conn.Execute(sql)
rs.MoveFirst()  #光标移到首条记录
count = 0
while True:
    if rs.EOF:
        break
    else:
        for i in range(rs.Fields.Count):
            #字段名：字段内容
            print(rs.Fields[i].Name, "：", rs.Fields[i].Value)
        count += 1
    rs.MoveNext()
